package com.qf.commons.sentinel.config;

import com.qf.commons.core.exception.IExceptionListener;
import com.qf.commons.sentinel.exception.SentinelExceptionHandler;
import com.qf.commons.sentinel.listener.SentinelExceptionListener;
import com.qf.commons.sentinel.nacos.NacosDatasourceConfig;
import com.qf.commons.sentinel.nacos.NacosDatasourceLoader;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * description: Sentinel模块自动装配的类
 * author: Ken
 * 公众号：Java架构栈
 */
@Configuration
@EnableConfigurationProperties(NacosDatasourceConfig.class)
public class SentinelConfiguration {

    /**
     * 注册异常处理类
     * @return
     */
    @Bean
    public SentinelExceptionHandler getExceptionHandler(){
        return new SentinelExceptionHandler();
    }

    /**
     * 注册Sentinel异常记录监听器
     * @return
     */
    @Bean
    public IExceptionListener getSentinelExceptionListener(){
        return new SentinelExceptionListener();
    }

    /**
     * 注册Nacos数据源加载器
     * @return
     */
    @Bean
    public NacosDatasourceLoader getNacosDatasourceLoader(){
        return new NacosDatasourceLoader();
    }
}
